﻿<%
'编辑器操作类
Class editorAction
	'路径前缀, 文件保存目录路径
	Private s_imgPreStr, s_uploadFolder
	'允许上传的图片/Flash/Media/文件-扩展名
	Private s_imgType, s_flsType, s_mdaType, s_fileType
	'允许上传的图片/Flash/Media/文件-大小
	Private s_imgSize, s_flsSize, s_mdaSize, s_fileSize
	'''构造
	Private Sub Class_Initialize()
		''载入Json和Upload类
		Response.CodePage=65001
		Response.Charset="UTF-8"
		Sa.Use("Fso")
		Sa.Use("Json")
		Sa.Use("Upload")
		checkSession_()
		s_imgPreStr = ""
		s_uploadFolder = "/data/upload/"
		s_imgType = "gif/jpg/jpeg/png/bmp"
		'允许上传图片大小2*1024*1024b=2M
		s_imgSize = 2097152
		s_flsType = "swf/flv"
		s_flsSize = 5242880
		s_mdaType = "swf/flv/mp3/wav/wma/wmv/mid/avi/mpg/asf/rm/rmvb"
		s_mdaSize = 5242880
		s_fileType = "doc/docx/xls/xlsx/ppt/htm/html/txt/zip/rar/gz/bz2"
		s_fileSize = 2097152
	End Sub
	
	'''析构
	Private Sub Class_Terminate()
		Set Upload = Nothing
		Set Json = Nothing
		Set Fso = Nothing
	End Sub

	'''返回图片信息json
	Private Sub showImg_(Byval p_filestr)
		Response.AddHeader "Content-Type", "application/Json; charset=UTF-8"
		Dim t_hash : Set t_hash = Json.New(0)
		t_hash("error") = 0
		t_hash("url") = p_filestr
		t_hash.Flush
	End Sub
	
	'''返回错误信息json
	Private Sub showError_(Byval p_message)
		Response.AddHeader "Content-Type", "application/Json; charset=UTF-8"
		Dim t_hash : Set t_hash = Json.New(0)
		t_hash("error") = 1
		t_hash("message") = p_message
		t_hash.Flush
		Response.End
	End Sub
	
	'''检测登录
	Private Sub checkSession_()
		If Session("adminid") = "" Then
			showError_("对不起,您还未登录或登录超时!")
		End If
	End Sub
	
	'''保存
	Public Sub save()
		Dim t_savePath : t_savePath = s_uploadFolder
		If Not Fso.IsFolder(t_savePath) Then
			'showError_(t_savePath)
			showError_("上传目录不存在。")
		End If
		Dim t_dirName : t_dirName = Request.QueryString("dir")
		If IsEmpty(t_dirName) Then
			t_dirName = "image"
		End If
		If InStr(Lcase("image,flash,media,file"), t_dirName) < 1 Then
			showError_("目录名不正确。")
		End If
		Dim t_maxSize, t_extStr, t_saveUrl
		Select Case Lcase(t_dirName)
		Case "flash"
			t_maxSize = s_flsSize
			t_extStr = s_flsType
		Case "media"
			t_maxSize = s_mdaSize
			t_extStr = s_mdaType
		Case "file"
			t_maxSize = s_fileSize
			t_extStr = s_fileType
		Case Else
			t_maxSize = s_imgSize
			t_extStr = s_imgType
		End Select
		'文件显示URL
		t_saveUrl = s_imgPreStr & t_savePath
		'创建YMD文件夹
		t_savePath = t_savePath & Year(Now()) & IIF(Month(Now())<10, "0"&Month(Now()), Month(Now())) & "/"
		t_saveUrl = t_saveUrl & Year(Now()) & IIF(Month(Now())<10, "0"&Month(Now()), Month(Now())) & "/"
		If Not Fso.CreateFolder(t_savePath) Then
			showError_("创建文件夹时发生错误。")
		End If
		Upload.FileType = t_extStr
		Upload.MaxSize = t_maxSize
		Upload.SavePath = t_savePath
		Upload.Open()
		Select Case Upload.error
		Case -1
			showError_("请选择文件。")
		Case 0
			showImg_(t_saveUrl & Upload.form("imgFile"))
		Case 1
			showError_("文件过大,应控制在"&t_maxSize/1024&"KB以内!")
		Case 2
			showError_("上传文件扩展名是不允许的扩展名！")
		Case 3
			showError_("上传文件扩展名是不允许的扩展名！")
		Case Else
			showError_("文件上传出错！")
		End Select
	End Sub
	
End Class
%>